<template>
    <div>
        <el-form ref="form" :model="obj.data" label-width="100px">
            <el-form-item label="banner" :rules="[formRulesMixin.notNull]">
                <UpFileS v-model:file="obj.data.img" dir="banner" />
            </el-form-item>
            <el-form-item label="排序" prop="sort" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.sort" clearable autocomplete="off" maxlength="11" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="所属小程序" prop="type" :rules="[formRulesMixin.notNull]">
                <el-select v-model="obj.data.type" placeholder="请选择所属小程序" class="search_select" clearable>
                    <el-option v-for="(item,index) in globalData.miniTypeList" :key="index" :label="item.text" :value="item.value" />
                </el-select>
            </el-form-item>
            <!-- <el-form-item label="跳转路径" prop="par">
                <el-input v-model="obj.data.par" clearable autocomplete="off"></el-input>
            </el-form-item> -->
            <el-form-item class="dialog-btns-item">
                <div class="dialog-btns">
                    <span class="btn clear" @click="$emit('close')">取消</span>
                    <span class="btn sub ml10" @click.prevent="upData">提交</span>
                </div>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { reactive,ref,getCurrentInstance,toRaw,inject } from 'vue'
    import UpFileS from "@/components/upfile_single.vue"
    let { proxy } = getCurrentInstance()
    let obj = reactive({
        data:{
            "id": inject("id").value || 0,
            "img_old":"",
            "img":"",
            "sort":"",
            "type":"",
            "par":"",
        },
    })

    let init = async () => {
        if(obj.data.id > 0){
            proxy.$ajax({
                url: 'banner/get',
                data: obj.data,
                bfLoading: true
            }).then(d => {
                // console.log(d)
                if(d.success){
                    obj.data = {...obj.data, ...d.msg}
                    obj.data.type = obj.data.type
                    obj.data.img_old = d.msg.img
                }else{
                    proxy.elMessageMixin(d.err, 'error')
                }
            }).catch(() => { })
        }
    }
    init()
    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                proxy.$ajax({
                    url: 'banner/design',
                    data: {...obj.data,par:''},
                    bfLoading: true,
                    // timeout:60000
                }).then(d => {
                    if(d.success){
                        proxy.elMessageMixin(`${obj.data.property_id>0?'修改':"添加"}成功`, 'success')
                        proxy.$emit('init')
                        proxy.$emit('close')
                    }else{
                        proxy.elMessageMixin(d.err, 'error')
                    }
                }).catch(() => { })
            }else{
                return false
            }
        })
    }
</script>

<style scoped>
</style>